<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/9
 * Time: 10:53
 */

namespace common\business;


class WebserviceHandler extends Handler
{
    /**
     * @param $record ActiveRecord
     * @param $log Log
     * @return bool
     */
    public function saveRecordWithLogUnsafe($record, $log){
        $actionIsSuccess = true;
        if (!$record->save()) {
            $dbErrorMsg = Json::encode($record->getErrors());
            $this->addError('SaveRecordWithLog', $dbErrorMsg);
            $log->memo = $log->memo . ' | ' . CommonResources::ACTION_FAIL_MSG('Save', 'Record', $dbErrorMsg);
            $actionIsSuccess = false;
        }
        if (!$log->save()) {
            $dbErrorMsg = Json::encode($log->getErrors());
            $this->addError('SaveRecordWithLog', $dbErrorMsg);
            $log->memo = $log->memo . ' | ' . CommonResources::ACTION_FAIL_MSG('Save', 'Record', $dbErrorMsg);
            Yii::error(CommonResources::ACTION_FAIL_MSG('Save', 'Log', $log->memo));
        }
        return $actionIsSuccess;
    }
}